using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using Director.StockSharp.Transaq.Native.Responses;

namespace Director.DomainModels
{
	[DataContract]
	public class Security : Identifiable
	{
		[DataMember]
		public int Decimals { get; set; }

		[DataMember]
		public int Lotsize { get; set; }

		[DataMember]
		public int MarketId { get; set; }

		[DataMember]
		public SecurityTypes Sectype { get; set; }

		[DataMember]
		public string Code { get; set; }

		[DataMember]
		public string Board { get; set; }

		internal Security(TransaqSecurity o): base(o.SecId, o.ShortName.Replace("\n",""))
		{
			Decimals = o.Decimals;
			MarketId = o.Market;
			Code = o.SecCode;
			Sectype = GetSecType(o.Type);
			Board = o.Board;
			Lotsize = GetLotSize();
		}

		private SecurityTypes GetSecType(SecurityTypes type)
		{
			if (Code.EndsWith(".MM"))
			{
				return SecurityTypes.SHARE;
			}
			if (Code.StartsWith("RTS") && char.IsDigit(Code.Last()))
			{
				return SecurityTypes.FUT;
			}
			return type;
		}

		private int GetLotSize()
		{
			int value;
			if (_lotSize.TryGetValue(Code, out value))
			{
				return value;
			}

			if (Sectype == SecurityTypes.FUT)
			{
				return 1;
			}
			return 0;
		}

		#region _lotSize

		private static readonly Dictionary<string, int> _lotSize = new Dictionary<string, int>
		                                                           {
			                                                           {"MSNG.MM", 1000},
			                                                           {"SCOH.MM", 10},
			                                                           {"ARMD.MM", 10},
			                                                           {"DZRD.MM", 1},
			                                                           {"DZRDP.MM", 1},
			                                                           {"DIOD.MM", 100},
			                                                           {"ISKJ.MM", 100},
			                                                           {"NEKK.MM", 100},
			                                                           {"ODVA.MM", 1000},
			                                                           {"RNAV.MM", 100},
			                                                           {"LIFE.MM", 100},
			                                                           {"RU14AVAN8010.MM", 10},
			                                                           {"UNAC.MM", 10000},
			                                                           {"AVAZ.MM", 100},
			                                                           {"AVAZPP.MM", 100},
			                                                           {"AGRE.MM", 100000},
			                                                           {"AZKM.MM", 10},
			                                                           {"AKRN.MM", 1},
			                                                           {"APDS.MM", 1},
			                                                           {"APDSP.MM", 1},
			                                                           {"RU14APTK1007.MM", 10},
			                                                           {"ARSA.MM", 1000},
			                                                           {"ASSB.MM", 1000},
			                                                           {"AMEZ.MM", 100},
			                                                           {"AFLT.MM", 100},
			                                                           {"PKBA.MM", 1},
			                                                           {"PKBAP.MM", 1},
			                                                           {"MMBM.MM", 1},
			                                                           {"BISV.MM", 100},
			                                                           {"BISVP.MM", 1000},
			                                                           {"BEGY.MM", 100},
			                                                           {"BELO.MM", 100},
			                                                           {"BACT.MM", 1000},
			                                                           {"BSPB.MM", 10},
			                                                           {"BSPBP.MM", 10},
			                                                           {"WBDF.MM", 1},
			                                                           {"VFRM.MM", 1},
			                                                           {"VSMO.MM", 1},
			                                                           {"VSMZ.MM", 1},
			                                                           {"VZRZ.MM", 1},
			                                                           {"VZRZP.MM", 10},
			                                                           {"VTEL.MM", 10},
			                                                           {"VTELP.MM", 10},
			                                                           {"VGSB.MM", 1000},
			                                                           {"VGSBP.MM", 1000},
			                                                           {"VOSB.MM", 100},
			                                                           {"VRAO.MM", 10000},
			                                                           {"RAOVP.MM", 10000},
			                                                           {"VTBR.MM", 10000},
			                                                           {"VTBS.MM", 100},
			                                                           {"VTGK.MM", 1000},
			                                                           {"VLHZ.MM", 10},
			                                                           {"VDSB.MM", 100},
			                                                           {"SIBN.MM", 10},
			                                                           {"GAZP.MM", 10},
			                                                           {"GMKN.MM", 1},
			                                                           {"RU0008913751.MM", 100},
			                                                           {"DASB.MM", 10000},
			                                                           {"DLVB.MM", 10},
			                                                           {"DLVBP.MM", 10},
			                                                           {"DLSVP.MM", 10},
			                                                           {"DLSV.MM", 10},
			                                                           {"DNKOP.MM", 100},
			                                                           {"FESH.MM", 100},
			                                                           {"DIKO.MM", 1000},
			                                                           {"DIXY.MM", 10},
			                                                           {"DGBZ.MM", 100},
			                                                           {"DGBZP.MM", 100},
			                                                           {"DVEC.MM", 1000},
			                                                           {"ERMK.MM", 100},
			                                                           {"ZMZN.MM", 10},
			                                                           {"ZMZNP.MM", 100},
			                                                           {"ZOYA.MM", 10},
			                                                           {"IKAR.MM", 10},
			                                                           {"IUES.MM", 100000},
			                                                           {"RU14INUR2017.MM", 10000},
			                                                           {"IRKT.MM", 100},
			                                                           {"IRGZ.MM", 100},
			                                                           {"KHEL.MM", 10},
			                                                           {"KLNA.MM", 10},
			                                                           {"KLSB.MM", 100},
			                                                           {"KMAZ.MM", 100},
			                                                           {"KCHE.MM", 10000},
			                                                           {"KCHEP.MM", 10000},
			                                                           {"TGKD.MM", 100000},
			                                                           {"TGKDP.MM", 100000},
			                                                           {"KZMS.MM", 10},
			                                                           {"KISB.MM", 10000},
			                                                           {"KISBP.MM", 10000},
			                                                           {"KMEZ.MM", 1},
			                                                           {"KUOS.MM", 10},
			                                                           {"KSGR.MM", 10},
			                                                           {"KOSB.MM", 1000},
			                                                           {"CMST.MM", 10},
			                                                           {"BENR.MM", 10},
			                                                           {"BENRP.MM", 10},
			                                                           {"KOGK.MM", 1},
			                                                           {"KRSG.MM", 10},
			                                                           {"RU0008913868.MM", 10},
			                                                           {"KROT.MM", 10},
			                                                           {"KRSB.MM", 1000},
			                                                           {"KRSBP.MM", 1000},
			                                                           {"KTSB.MM", 10000},
			                                                           {"KTSBP.MM", 10000},
			                                                           {"KUSTP.MM", 100},
			                                                           {"KBSB.MM", 10},
			                                                           {"KUBE.MM", 10},
			                                                           {"KZBN.MM", 10000},
			                                                           {"KBTK.MM", 10},
			                                                           {"LNZLP.MM", 1},
			                                                           {"LNZL.MM", 1},
			                                                           {"LSNG.MM", 100},
			                                                           {"LSNGP.MM", 100},
			                                                           {"LSRG.MM", 1},
			                                                           {"LKOH.MM", 1},
			                                                           {"MVID.MM", 10},
			                                                           {"MAGE.MM", 1000},
			                                                           {"MAGEP.MM", 1000},
			                                                           {"MGNT.MM", 1},
			                                                           {"RU14MBSP7002.MM", 10},
			                                                           {"RU14MGTS2012.MM", 10},
			                                                           {"RU14MGTS5007.MM", 10},
			                                                           {"MDMBP.MM", 100},
			                                                           {"RU0009011126.MM", 10},
			                                                           {"RU0009011134.MM", 10},
			                                                           {"IRSG.MM", 1},
			                                                           {"MERF.MM", 1000},
			                                                           {"MTLR.MM", 1},
			                                                           {"MIKR.MM", 1},
			                                                           {"MAGN.MM", 100},
			                                                           {"MRSB.MM", 10000},
			                                                           {"MNPZ.MM", 1},
			                                                           {"MSTT-001D.MM", 10},
			                                                           {"MSTT.MM", 10},
			                                                           {"MSSV.MM", 10000},
			                                                           {"MSSB.MM", 10000},
			                                                           {"MOTZ.MM", 1000},
			                                                           {"MSRS.MM", 1000},
			                                                           {"MRKZ.MM", 10000},
			                                                           {"MRKK.MM", 10},
			                                                           {"MRKU.MM", 10000},
			                                                           {"MRKC.MM", 1000},
			                                                           {"MRKP.MM", 10000},
			                                                           {"MRKV.MM", 10000},
			                                                           {"MRKS.MM", 10000},
			                                                           {"MRKA.MM", 10000},
			                                                           {"MTSI.MM", 10},
			                                                           {"NNSB.MM", 1},
			                                                           {"NNSBP.MM", 1},
			                                                           {"RU14NZGZ2006.MM", 1000},
			                                                           {"NKNC.MM", 100},
			                                                           {"NKNCP.MM", 100},
			                                                           {"NLMK.MM", 10},
			                                                           {"NMTP.MM", 1000},
			                                                           {"NOTK.MM", 10},
			                                                           {"SXPNP.MM", 1},
			                                                           {"NONG.MM", 1},
			                                                           {"NTRI.MM", 100},
			                                                           {"OSFD.MM", 1000},
			                                                           {"OGK1.MM", 1000},
			                                                           {"OGK1-002D.MM", 1000},
			                                                           {"OGK2.MM", 1000},
			                                                           {"OGKC.MM", 1000},
			                                                           {"OGK4.MM", 1000},
			                                                           {"OGKE.MM", 1000},
			                                                           {"OGK6.MM", 1000},
			                                                           {"OMZZ.MM", 100},
			                                                           {"OMZZP.MM", 1},
			                                                           {"OSMP.MM", 100},
			                                                           {"OMSH.MM", 10},
			                                                           {"OPIN.MM", 1},
			                                                           {"OPTI.MM", 1},
			                                                           {"AKHA.MM", 100},
			                                                           {"PMOT.MM", 1000},
			                                                           {"PMSB.MM", 10},
			                                                           {"PMSBP.MM", 10},
			                                                           {"PBSB.MM", 100},
			                                                           {"PIKK.MM", 10},
			                                                           {"PRIM.MM", 1000},
			                                                           {"PNTZ.MM", 100},
			                                                           {"PMTL.MM", 10},
			                                                           {"PLZL.MM", 1},
			                                                           {"RU14PRMB1006.MM", 1},
			                                                           {"RU14PRMB2004.MM", 1},
			                                                           {"RU14PRMB3002.MM", 1},
			                                                           {"RU14PRMB4000.MM", 1},
			                                                           {"RU14PRMB5007.MM", 1},
			                                                           {"RU14PRMB6005.MM", 1},
			                                                           {"PRIN.MM", 1000},
			                                                           {"NPE1.MM", 1},
			                                                           {"PRTK.MM", 100},
			                                                           {"GRAZ.MM", 100},
			                                                           {"RASP.MM", 10},
			                                                           {"RBCI.MM", 100},
			                                                           {"RBCM.MM", 100},
			                                                           {"REBR.MM", 100},
			                                                           {"RODNP.MM", 100},
			                                                           {"ROSB.MM", 10},
			                                                           {"RVST.MM", 1},
			                                                           {"ROST.MM", 10},
			                                                           {"ROSN.MM", 10},
			                                                           {"RTKM.MM", 10},
			                                                           {"RTKMP.MM", 100},
			                                                           {"RTSB.MM", 10000},
			                                                           {"RTSBP.MM", 10000},
			                                                           {"RTMC.MM", 1000},
			                                                           {"RUALR.MM", 10},
			                                                           {"HYDR.MM", 1000},
			                                                           {"RUGR.MM", 1},
			                                                           {"RUSP.MM", 10000},
			                                                           {"RSEA.MM", 100},
			                                                           {"RZSB.MM", 1000},
			                                                           {"SNOS.MM", 1},
			                                                           {"SBER.MM", 10},
			                                                           {"SBERP.MM", 100},
			                                                           {"SVSB.MM", 1000},
			                                                           {"SVSBP.MM", 1000},
			                                                           {"SOVT.MM", 1},
			                                                           {"CHMF.MM", 10},
			                                                           {"SELL.MM", 1},
			                                                           {"SZPR.MM", 10},
			                                                           {"SPTL.MM", 100},
			                                                           {"SPTLP.MM", 100},
			                                                           {"STKM.MM", 1000},
			                                                           {"STKMP.MM", 1000},
			                                                           {"SILM.MM", 100},
			                                                           {"SILV.MM", 1},
			                                                           {"SYNG.MM", 1},
			                                                           {"SNTZ.MM", 1},
			                                                           {"HALS.MM", 1},
			                                                           {"AFKC.MM", 100},
			                                                           {"JNOS.MM", 100},
			                                                           {"JNOSP.MM", 100},
			                                                           {"MGNZ.MM", 1},
			                                                           {"SVAV.MM", 10},
			                                                           {"STSB.MM", 1000},
			                                                           {"STSBP.MM", 1000},
			                                                           {"SVTZ.MM", 10},
			                                                           {"YKST.MM", 1},
			                                                           {"SUMZ.MM", 10},
			                                                           {"SNGS.MM", 100},
			                                                           {"SNGSP.MM", 100},
			                                                           {"SKRN.MM", 1000},
			                                                           {"SEMZ.MM", 10},
			                                                           {"TAVR.MM", 1000},
			                                                           {"TAMZ.MM", 100},
			                                                           {"TASB.MM", 10000},
			                                                           {"TASBP.MM", 10000},
			                                                           {"TGMK.MM", 1000},
			                                                           {"TATB.MM", 10},
			                                                           {"RU14TATN3006.MM", 10},
			                                                           {"RU14TATN3014.MM", 10},
			                                                           {"TTLK.MM", 10000},
			                                                           {"TGKA.MM", 100000},
			                                                           {"TGKK.MM", 100000},
			                                                           {"TGK13.MM", 10000},
			                                                           {"TGKN.MM", 1000000},
			                                                           {"TGKB.MM", 1000000},
			                                                           {"TGKBP.MM", 1000000},
			                                                           {"TGKE.MM", 100000},
			                                                           {"TGKF.MM", 100000},
			                                                           {"TGKI.MM", 1000000},
			                                                           {"CNTL.MM", 100},
			                                                           {"TUZA.MM", 10},
			                                                           {"TUCH.MM", 10},
			                                                           {"TRMK.MM", 10},
			                                                           {"TNBP.MM", 100},
			                                                           {"TNBPP.MM", 100},
			                                                           {"TORS.MM", 10000},
			                                                           {"TORSP.MM", 10000},
			                                                           {"TRCN.MM", 1},
			                                                           {"TRNFP.MM", 1},
			                                                           {"TCBN.MM", 100},
			                                                           {"TSKA.MM", 1},
			                                                           {"UAZA.MM", 1000},
			                                                           {"UDSB.MM", 1000},
			                                                           {"UDSBP.MM", 1000},
			                                                           {"URFD.MM", 1000},
			                                                           {"URSI.MM", 1000},
			                                                           {"URSIP.MM", 1000},
			                                                           {"URKA.MM", 10},
			                                                           {"UUAZ.MM", 100},
			                                                           {"PHST.MM", 1},
			                                                           {"FSRV.MM", 1000},
			                                                           {"FLKO.MM", 100},
			                                                           {"TGKJ.MM", 100},
			                                                           {"FEES.MM", 10000},
			                                                           {"MRKH.MM", 1000},
																	   {"RSTI.MM", 1000},
			                                                           {"MRKHP.MM", 1000},
			                                                           {"CTLK.MM", 100},
			                                                           {"CTLKP.MM", 100},
			                                                           {"WTCM.MM", 100},
			                                                           {"WTCMP.MM", 1000},
			                                                           {"TZUM.MM", 100},
			                                                           {"CLSB.MM", 10000},
			                                                           {"CLSBP.MM", 10000},
			                                                           {"GCHE.MM", 1},
			                                                           {"CHKZ.MM", 1},
			                                                           {"CHMK.MM", 1},
			                                                           {"CHEP.MM", 100},
			                                                           {"CHZN.MM", 10},
			                                                           {"RKKE.MM", 1},
			                                                           {"NGSB.MM", 1000},
			                                                           {"NGSBP.MM", 1000},
			                                                           {"ERAV.MM", 10000},
			                                                           {"UKUZ.MM", 1},
			                                                           {"UTEL.MM", 1000},
			                                                           {"UTELP.MM", 1000},
			                                                           {"UTAR.MM", 100},
			                                                           {"YKENP.MM", 10000},
			                                                           {"YKEN.MM", 10000},
			                                                           {"YRSL.MM", 10},
																	   {"TATN.MM", 10},
																	   {"BANE.MM", 1},
																	   {"IRAO.MM", 1000},
																	   {"MTSS.MM", 10},
																	   {"NVTK.MM", 10},
																	   {"OGKB.MM", 1000},
};

		#endregion

	}
}